package com.zhuiyun.project.api.joingroup.controller;

import com.zhuiyun.project.api.joingroup.entity.JoinGroup;
import com.zhuiyun.project.api.joingroup.model.JoinGroupModel;
import com.zhuiyun.project.api.joingroup.service.JoinGroupService;
import com.zhuiyun.project.api.messagelist.model.MessageListModel;
import com.zhuiyun.project.api.messagelist.service.MessageListService;
import com.zhuiyun.project.common.response.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName JoinGroupController
 * @Description TODO
 * @Author kdj
 * @Date 2023/7/24 17:16
 **/
@RestController
@CrossOrigin
@RequestMapping("/joinGroup")
public class JoinGroupController {
    @Autowired
    private JoinGroupService groupService;

    /**
     * @param joinGroupModel
     * @Author kdj
     * @Description 申请加入群聊 系统人员
     * @Date 2023/7/25 21:39
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/toJoinGroupSys")
    public CommonResult toJoinGroupSys(@RequestBody JoinGroupModel joinGroupModel) {
        return groupService.toJoinGroupSys(joinGroupModel);
    }


    /**
     * @Author 小江
     * @Description //TODO 判断是否在禁言中
     * @Date 11:25 2023/7/31
     **/
    @GetMapping("/stormroup")
    public CommonResult stormroup(int userId, int groupId) {
        return CommonResult.ok(groupService.stormroup(userId, groupId));
    }


    /**
     * @Author 小江
     * @Description //TODO 根据群号查询群成员
     * @Date 8:44 2023/7/27
     **/
    @GetMapping("/setByGroupId")
    @ApiOperation(value = "根据群号查询群成员")
    public CommonResult setByGroupId(int groupId) {
        return groupService.setByGroupId(groupId);
    }

    /**
     * @param groupId
     * @param userId
     * @Author kdj
     * @Description 根据群号查询群成员
     * @Date 2023/8/10 18:43
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/setlinkGroupId")
    @ApiOperation(value = "根据群号查询群成员")
    public CommonResult setLinkGroupId(int groupId, int userId) {
        return groupService.setLinkGroupId(groupId, userId);
    }

    /**
     * @Author 小江
     * @Description //TODO 踢出群聊
     * @Date 9:52 2023/7/28
     **/
    @DeleteMapping("groupDel")
    CommonResult groupDel(Integer fromId, Integer toId, String groupName,String value) {
        int i = groupService.groupDel(fromId, toId, groupName,value);
        if (i > 0) {
            return CommonResult.ok("成功踢出用户");
        } else {
            return CommonResult.error("踢出用户失败");
        }
    }


    /**
     * @param joinGroupModel
     * @Author kdj
     * @Description 自动退出
     * @Date 2023/8/11 8:56
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("plainDel")
    CommonResult plainDel(@RequestBody JoinGroupModel joinGroupModel) {
        int i = groupService.plainDel(joinGroupModel.getUserId(), joinGroupModel.getGroupId());
        if (i > 0) {
            return CommonResult.ok("退出成功");
        } else {
            return CommonResult.error("退出失败");
        }
    }


    /**
     * @Author 小江
     * @Description //TODO 添加禁言时间
     * @Date 10:11 2023/7/28
     **/
    @PostMapping("/joinins")
    public CommonResult joinins(@RequestBody MessageListModel model) {
        int i = groupService.joinins(model);
        if (i > 0) {
            return CommonResult.ok("禁言成功");
        } else {
            return CommonResult.error(9999, "禁言失败");
        }
    }

    /**
     * @Author 小江
     * @Description //TODO 解除禁言
     * @Date 10:11 2023/7/28
     **/
    @PostMapping("relievetime")
    CommonResult relievetime(@RequestBody MessageListModel model) {
        int i = groupService.relievetime(model);
        if (i > 0) {
            return CommonResult.ok("成功解除");
        } else {
            return CommonResult.error("解除失败");
        }
    }

    /**
     * @param joinGroupModel
     * @Author kdj
     * @Description 申请加入群聊 app
     * @Date 2023/7/25 21:39
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/toJoinGroupApp")
    public CommonResult toJoinGroupApp(@RequestBody JoinGroupModel joinGroupModel) {
        return groupService.toJoinGroupApp(joinGroupModel);
    }

    /**
     * @param userId
     * @Author kdj
     * @Description 获取入群审核
     * @Date 2023/7/27 16:23
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getJoinGroupAudits")
    public CommonResult getJoinGroupAudits(int userId) {
        return groupService.getJoinGroupAudits(userId);
    }

    /**
     * @param userId
     * @Author kdj
     * @Description 获取我申请过的入群审核
     * @Date 2023/7/27 16:23
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getJoinGroupAuditByMe")
    public CommonResult getJoinGroupAuditByMe(int userId) {
        return CommonResult.ok(groupService.getJoinGroupAuditByMe(userId));
    }


    /**
     * @param createUserId
     * @Author kdj
     * @Description 获取未处理的未读数
     * @Date 2023/7/27 20:34
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getUnReadJoinGroup")
    public CommonResult getUnReadJoinGroup(int createUserId) {
        return groupService.getUnReadJoinGroup(createUserId);
    }


    /**
     * @param joinGroupModel
     * @Author kdj
     * @Description 审核拒绝加入群聊
     * @Date 2023/7/28 10:59
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/toNoJoin")
    public CommonResult toNoJoin(@RequestBody JoinGroupModel joinGroupModel) {
        return groupService.toNoJoin(joinGroupModel);
    }

    /**
     * @param joinGroupModel
     * @Author kdj
     * @Description 审核同意入群聊
     * @Date 2023/7/28 15:35
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/toOkJoin")
    public CommonResult toOkJoin(@RequestBody JoinGroupModel joinGroupModel) {
        return groupService.toOkJoin(joinGroupModel);
    }

    @GetMapping("/getJoinGroupByGroupId")
    public CommonResult getJoinGroupByGroupId(int fromId, int groupId) {
        return groupService.stormFriend(fromId, groupId);
    }
}
